package org.example.graph;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Kruskal {
    public static HashMap<Node, List<Node>> setMap;
    public static class MySets{

        public MySets(List<Node> nodes) {
            for (Node cur : nodes) {
                ArrayList<Node> set = new ArrayList<>();
                set.add(cur);
                setMap.put(cur,set);
            }
        }
    }
    public boolean isSameSet(Node from,Node to) {
        List<Node> fromSet = setMap.get(from);
        List<Node> toSet = setMap.get(to);
        return fromSet == toSet;
    }

    public void  union(Node from,Node to) {
        List<Node> fromSet = setMap.get(from);
        List<Node> toSet = setMap.get(to);
        for (Node toNode : toSet) {
            fromSet.add(toNode);
            setMap.put(toNode,fromSet);
        }
    }
}
